-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Support for legacy source
prop when value is TemplateLiteral
#245
Conversation
Why are we turning the original What is stopping this from working: from v4 syntax <Story source={generatedSource()} /> to v4 syntax <Story parameters={{ docs: { source: { code: generatedSource() } } }} /> I'm sorry for my ignorance. |
Do you mean moving the entire AST node object for whatever value is set inside Well, that's easy. Let's break down the type of what
The 3rd one, I really don't like it. Is one of the valid Svelte syntax, and I wouldn't be surprised if maintainers ever regret inventing this one too now. This this "feature": <Component prop="Some text with dynamic {value}, and can have more {values}" /> From user perspective, meh. From AST perspective, I don't love it 😅 |
On the second thought... it becomes array Meaning if there's no 'interpolation' via <!-- (AST.Text | AST.ExpressionTag)[] 👇 because of and 👇 -->
<Component prop="Some text with dynamic {value}, and can have more {values}" /> <!-- 👇 this is just an AST.ExpressionTag -->
<Component prop="Some text with literal value" /> So, what we could do is omit/throw error when value is an array and just forward the AST node for attribute value into object expression ( |
To me it looks like that from
to
Could we do the same? Maybe there's some code we can lift directly from the Svelte repo. Regardless, I'm not sure how complicated that would be, and this fix here is better than nothing, I'm just exploring if we can make it even more dynamic and try to be less smart, but that shouldn't block this PR. |
Let me see if I can find in their internals a function that we can copy. Thanks for the idea! |
Credits for debugging/finding goes to @dominikg via Storybook Discord
There's only one question: Should we call
.trim()
on the extracted template literal value?EDIT. Based on this Storybook test preview (bottom-right corner - Show code) it seems whitespaces are already handled internally in the core. I'm guessing. So, the answer might be no.